package com.xlhj.yucloud.controller;

import com.xlhj.yucloud.common.ResultData;
import com.xlhj.yucloud.entity.SysDictInfo;
import com.xlhj.yucloud.service.SysDictInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: caijliu
 * @Date: 11/10/2021 10:04
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@RestController
@RequestMapping("/system/dict")
@RequiredArgsConstructor
public class SysDictController {

    private final SysDictInfoService dictInfoService;

    @PostMapping("/addDictInfo")
    public ResultData addDictInfo(@RequestBody SysDictInfo dictInfo) {
        return ResultData.success().data(dictInfoService.save(dictInfo));
    }

    @PutMapping("/updateDictInfo")
    public ResultData updateDictInfo(@RequestBody SysDictInfo dictInfo) {
        return ResultData.success().data(dictInfoService.updateById(dictInfo));
    }

    @DeleteMapping("/delDictById/{id}")
    public ResultData delDictById(@PathVariable("id") Long id) {
        SysDictInfo dictInfo = new SysDictInfo();
        dictInfo.setId(id);
        return ResultData.success().data(dictInfoService.removeById(dictInfo));
    }
}
